package com.endbd.systemmanagement.service.dept;

import com.endbd.feignapi.model.system.Dept;
import com.endbd.systemmanagement.dao.dept.DeptDao;
import com.endbd.systemmanagement.model.DeptCondition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DeptServiceImpl implements DeptService{


  @Autowired
  private DeptDao deptDao;

  @Override
  public List<Dept> getDeptList() {
    return deptDao.getDeptList();
  }

  @Override
  public List<Dept> getDeptInfoList(DeptCondition deptCondition) {
    return deptDao.getDeptInfoList(deptCondition);
  }

  @Override
  public int createDept(Dept dept) {
    Integer id=dept.getDeptId();
    int i=0;
    i=deptDao.queryId(id);
    if(i>0) return 2;
    String deptName = dept.getDeptName();
    i=deptDao.queryName(deptName);
    if(i>0) return 3;
    dept.setDeptState("1");
    return deptDao.createDept(dept);
  }

  @Override
  public boolean zhuxaio(int id, String state) {
    if("1".equals(state)) state="0";
    else state="1";
    return deptDao.zhuxiao(id,state)==1;
  }

  @Override
  public Dept getDept(Integer did) {
    return deptDao.getDept(did);
  }

  @Override
  public boolean updateDept(Dept dept) {
    return deptDao.updateDept(dept)==1;
  }
}
